#define _GNU_SOURCE

#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

void sigHandler(int sig){
    printf("Recive signal %d %s\n", sig, strsignal(sig));
}


int main(){
    struct sigaction act;
    sigset_t set;

    act.sa_handler = &sigHandler;

    if(sigaction(SIGCONT, &act, NULL) == -1){
        printf("Error sigaction SIGCONT %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    sigemptyset(&set);
    sigaddset(&set, SIGCONT);
    if(sigprocmask(SIG_BLOCK, &set, NULL) == -1){
        printf("Error set sigprocmask SIG_BLOCK signal SIGCONT%s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    printf("Pid = %d, lock SIGCONT, raise() and wait SIGCONT\n", getpid());
    raise(SIGSTOP);
    puts("Unlock SIGCONT");
    if(sigprocmask(SIG_UNBLOCK, &set, NULL) == -1){
        printf("Error set sigprocmask SIG_UNBLOCK signal SIGCONT%s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    puts("Finish");
    exit(EXIT_SUCCESS);
}